<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  
  
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>
    
    M_W_Q</title>
  
    <link rel="shortcut icon" href="/bolg/favicon.ico">
  
  <link rel="stylesheet" href="/bolg/css/style.css">
  
    <link rel="stylesheet" href="/bolg/fancybox/jquery.fancybox.min.css">
  
  <script src="/bolg/js/pace.min.js"></script>
</head>

<body>
<main class="content">
  <section class="jumbotron">
  <div class="video">
    
      <div class="video-frame">
        <img src="/bolg/images/ocean/overlay-hero.png" alt="Decorative image frame">
      </div>
    
    <div class="video-media">
      <video playsinline="" autoplay="" loop="" muted="" data-autoplay=""
             poster="/bolg/images/ocean/ocean.png" x5-video-player-type="h5">
        <source src="/bolg/images/ocean/ocean.mp4" type="video/mp4">
        <source src="/bolg/images/ocean/ocean.ogv" type="video/ogg">
        <source src="/bolg/images/ocean/ocean.webm" type="video/webm">
        <p>Your user agent does not support the HTML5 Video element.</p>
      </video>
      <div class="video-overlay"></div>
    </div>
    <div class="video-inner text-center text-white">
      <h1><a href="/bolg/">M_W_Q</a></h1>
      <p></p>
      <div><img src="/bolg/images/hexo-inverted.svg" class="brand" alt="M_W_Q"></div>
    </div>
    <div class="video-learn-more">
      <a class="anchor" href="#landingpage"><i class="fe fe-mouse"></i></a>
    </div>
  </div>
</section>

<div id="landingpage">
  <section class="outer">
  <article class="articles">
    
    <h1 class="page-type-title"></h1>

    
      
        

<article id="post-你需要了解的JSON知识" class="article article-type-post" itemscope itemprop="blogPost" data-scroll-reveal>
  
  <div class="article-inner">
    
      <header class="article-header">
        
  
    <h2 itemprop="name">
      <a class="article-title" href="/bolg/2019/10/21/%E4%BD%A0%E9%9C%80%E8%A6%81%E4%BA%86%E8%A7%A3%E7%9A%84JSON%E7%9F%A5%E8%AF%86/">你需要了解的JSON知识</a>
    </h2>
  
  




      </header>
    

    
      <div class="article-meta">
        <a href="/bolg/2019/10/21/%E4%BD%A0%E9%9C%80%E8%A6%81%E4%BA%86%E8%A7%A3%E7%9A%84JSON%E7%9F%A5%E8%AF%86/" class="article-date">
  <time datetime="2019-10-21T14:06:44.887Z" itemprop="datePublished">2019-10-21</time>
</a>
        
      </div>
    

    

    <div class="article-entry" itemprop="articleBody">
      


      

      
        <h2 id="你需要了解的JSON知识"><a href="#你需要了解的JSON知识" class="headerlink" title="你需要了解的JSON知识"></a><strong>你需要了解的JSON知识</strong></h2><h2 id="Json是什么？"><a href="#Json是什么？" class="headerlink" title="Json是什么？"></a><em>Json是什么？</em></h2><ul>
<li>JSON是一种数据交换模式，它被许都多的系统用于数据之间的交换。</li>
<li>JSON独立于编程语言，虽然的JSON（JavaScript Object Notation）的英文感觉是和JavaScript是息息相关的，但是你用自己的编程语言是完全没有问题的。而且你并不需要先学习JavaScript。</li>
<li>JSON拥有很好的可移植性。</li>
</ul>
<h2 id="Json的基本语法"><a href="#Json的基本语法" class="headerlink" title="Json的基本语法"></a><em>Json的基本语法</em></h2><ul>
<li><p>名称-值对<br>如果是有编程基础的人会对这个很了解的，键值对的形式非常的多（例如：大家非常熟悉的java语言，最典型的就是java的map）。<br>非常简单的例子，例如：</p>
  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">     &quot;name&quot;: &quot;M&quot;,</span><br><span class="line">      &quot;age&quot;: 18</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>简单的name，age就是名称，值就是M，18。这就是一个简单的json，有些需要注意的下面给大家慢慢讲。</p>
<ul>
<li>json的正确语法<br>上面的实例中可以看出，名称是必须要有双引号，如果你了解的话，就可以看出如果没有上引号就和JavaScript相同了。下面就是整个json中的一些符号的作用：<ul>
<li>{ ： 开始读对象</li>
<li>} ： 结束读对象</li>
<li>[ ： 开始读数组</li>
<li>] ： 结束读数组</li>
<li>: ：名称和值的分离</li>
<li>, ：新的一部分的开始<br>使用中其实并没有对键值中的命名有过多的要求，当然可以包括空格等一些特殊字符，由于我们需要发挥它的可移植性一般情况下我们是命名是不会加一些特殊的字符和空格的。</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="Json的数据类型"><a href="#Json的数据类型" class="headerlink" title="Json的数据类型"></a><em>Json的数据类型</em></h2><ul>
<li><p>对象</p>
<ul>
<li>下面就是一个很简单的例子，最高一级的名称是person，它对应的是有两个数据的对象值。<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">        </span><br><span class="line">    &#123;</span><br><span class="line">      &quot;person&quot;: &#123;</span><br><span class="line">        &quot;name&quot;: &quot;M&quot;,</span><br><span class="line">        &quot;age&quot;: 18</span><br><span class="line">      &#125;,</span><br><span class="line">      &quot;persion&quot;: &#123;</span><br><span class="line">        &quot;name&quot;: &quot;Q&quot;,</span><br><span class="line">        &quot;age&quot;: 20</span><br><span class="line">      &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p>字符串</p>
<ul>
<li>字符串是其实上面的每个例子都是有提到的，那就是name这个属性，所以就不在这进行写例子了，字符串需要注意到的是在写的时候你可能会有些些特殊的字符，一般来说是不建议写的但是也是有办法可以写的那就是加入转译符。<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">\/  正斜线</span><br><span class="line">\b  退格符</span><br><span class="line">\f  换页符</span><br><span class="line">\t  制表符</span><br><span class="line">\n  换行符</span><br><span class="line">\r  回车符</span><br><span class="line">\u  后面跟16进制的字符</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>数字</p>
<ul>
<li>整型</li>
<li>浮点型<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    &quot;a&quot;: 12,</span><br><span class="line">    &quot;b&quot;: 12.5,</span><br><span class="line">    &quot;c&quot;: -12</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p>布尔值</p>
<ul>
<li>false</li>
<li>true</li>
</ul>
</li>
<li><p>null</p>
<ul>
<li>null代表的没有值不要和JavaScript的undefined混淆，并且null必须是小写的,记得不要用上引号，不然那就是普通的字符串了</li>
</ul>
</li>
<li><p>数组</p>
<ul>
<li><p>索引是在0开始的。</p>
</li>
<li><p>数值中可以存放不同的数据类型</p>
  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">        &#123;</span><br><span class="line">           &quot;names&quot;: [</span><br><span class="line">           &quot;Bob&quot;,</span><br><span class="line">           &quot;Allen&quot;,</span><br><span class="line">           &quot;Hello&quot;</span><br><span class="line">         ],</span><br><span class="line">           &quot;ages&quot;: [</span><br><span class="line">           12,</span><br><span class="line">           23,</span><br><span class="line">           34</span><br><span class="line">       ],</span><br><span class="line">           &quot;other&quot;: [</span><br><span class="line">          &quot;name&quot;,</span><br><span class="line">          2,</span><br><span class="line">         null</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h2 id="结束语"><a href="#结束语" class="headerlink" title="结束语"></a><em>结束语</em></h2><p>Json的简单的简绍今天就到这里，以有时间会给在写写JSON Schema，Json的校验机制，他会对数据的输入和参数类型进行一个校验。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://m_aleen.gitee.io/bolg/2019/10/21/%E4%BD%A0%E9%9C%80%E8%A6%81%E4%BA%86%E8%A7%A3%E7%9A%84JSON%E7%9F%A5%E8%AF%86/" data-id="ck32z8ytr000569db64l036li"
         class="article-share-link">Share</a>
      
    </footer>

  </div>

  

  

</article>



      
  </article>
  

  
    <nav class="page-nav">
      
      <a class="extend prev" rel="prev" href="/bolg/">Prev page</a><a class="page-number" href="/bolg/">1</a><span class="page-number current">2</span>
    </nav>
  
</section>
</div>

  <footer class="footer">
  <div class="outer">
    <div class="float-right">
      <ul class="list-inline">
  
    <li><i class="fe fe-smile-alt"></i> <span id="busuanzi_value_site_uv"></span></li>
  
    <li><i class="fe fe-bookmark"></i> <span id="busuanzi_value_page_pv"></span></li>
  
</ul>
    </div>
    <ul class="list-inline">
      <li>&copy; 2019 M_W_Q</li>
      <li>Powered by <a href="http://hexo.io/" target="_blank">Hexo</a></li>
      <li>Theme  <a href="https://github.com/zhwangart/hexo-theme-ocean" target="_blank" rel="noopener">Ocean</a></li>
    </ul>
  </div>
</footer>

</main>

  <aside class="sidebar">
    
    <button class="navbar-toggle"></button>
<nav class="navbar">
  
    <div class="logo">
      <a href="/bolg/"><img src="/bolg/images/hexo.svg" alt="M_W_Q"></a>
    </div>
  
  <ul class="nav nav-main">
    
      <li class="nav-item">
        <a class="nav-item-link" href="/bolg/">Home</a>
      </li>
    
      <li class="nav-item">
        <a class="nav-item-link" href="/bolg/archives">Archives</a>
      </li>
    
      <li class="nav-item">
        <a class="nav-item-link" href="/bolg/gallery">Gallery</a>
      </li>
    
      <li class="nav-item">
        <a class="nav-item-link" href="/bolg/about">About</a>
      </li>
    
    <li class="nav-item">
      <a class="nav-item-link nav-item-search" title="搜索">
        <i class="fe fe-search"></i>
        Search
      </a>
    </li>
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      <div class="totop" id="totop">
  <i class="fe fe-rocket"></i>
</div>
    </li>
    <li class="nav-item">
      
        <a class="nav-item-link" target="_blank" href="/bolg/atom.xml" title="RSS Feed">
          <i class="fe fe-feed"></i>
        </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
  </aside>
  <script src="/bolg/js/jquery-2.0.3.min.js"></script>
<script src="/bolg/js/jquery.justifiedGallery.min.js"></script>
<script src="/bolg/js/lazyload.min.js"></script>
<script src="/bolg/js/busuanzi-2.3.pure.min.js"></script>

  <script src="/bolg/fancybox/jquery.fancybox.min.js"></script>




<script src="/bolg/js/ocean.js"></script>

</body>
</html>